package server2;

import org.apache.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;


/**
 * 閸氭垵顓归幋椋庮伂閸欐垶鏆熼幑顔芥閻ㄥ嫮绮嶉幋鎰佸锟�
 * 
 * @author Feng
 * 
 */
public class MinaEncoder extends ProtocolEncoderAdapter {
	Logger logger = Logger.getLogger(this.getClass());

	@Override
	public void encode(IoSession ioSession, Object message, ProtocolEncoderOutput output) throws Exception {
	
//		PacketLikePhoton pk = (PacketLikePhoton)message;
//		byte[] bytes = pk.getData().array();
       
		byte[] bytes = (byte[])message;
		int length = bytes.length;
//		IoBuffer buffer = IoBuffer.allocate(length + 4); 
		IoBuffer buffer = IoBuffer.allocate(length); 
		
//        buffer.putInt(length); // write header  
        buffer.put(bytes); // write body  
        buffer.flip();  
        output.write(buffer);
	}
}
